// pages/activity/nationalDay/components/TopTaskList/TopTaskList.js
import {
  taskList
} from './index.js'
import {
  getTaskList
} from '../../../../../api/activity'
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    taskList: [],
  },
  lifetimes: {
    attached() {
      this.initTaskList()
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    initTaskList() {
      const baseTaskIconUrl = 'https://ustatic.hudongmiao.com/joymewApp/activity/nationalDay/Dialog/taskList/';
      getTaskList().then(res => {
          console.log(res)
          if (res.data.list1) {
            let list = res.data.list1.map(item => {
              const {
                size,
                MayEventData
              } = item
              const {
                icon,
                button,
                context,
                splid,
                limit,
                score
              } = MayEventData
              let desc = `积分值+${score}`
              // if(score){
              // 	desc = `积分值+${score}，${size}/${limit}`
              // }
              if (limit && limit > 0) {
                desc = `积分值+${score}，${size}/${limit}`
              }
              let descMoreMap = {
                'complete_splid': '/场 (封顶4场)',
                'Flow_Hd': '(1元等于1分)',
                // 'wawa_pay': '/单',
              }
              if (descMoreMap[splid]) {
                desc += descMoreMap[splid]
              }
              let iconURl = `${baseTaskIconUrl}/${icon}.png`
              return {
                splid,
                size,
                ...MayEventData,
                id: icon,
                title: context,
                // desc: "积分值+50，1/1",
                action: splid,
                btnText: button,
                desc,
                iconURl,
                // icon: `@{baseTaskIconUrl}/icon.png`
              }
            })
            // this.taskList = list
            this.setData({
              taskList: list
            })
          }
        })
        .catch(err => {
          console.warn(err)
        })
    },
    sendTask(e) {
      const {
        action
      } = e.currentTarget.dataset
      this.triggerEvent('excute', action)
    }
  }
})